<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 信息科管理系统</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        .login-container {
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: linear-gradient(135deg, #409EFF, #36cccb);
        }
        .login-box {
            width: 90%;
            max-width: 400px;
            padding: 30px;
            background: white;
            border-radius: 12px;
            box-shadow: 0 8px 24px rgba(0,0,0,0.1);
        }
        .login-title {
            text-align: center;
            margin-bottom: 30px;
            color: #333;
        }
        .form-item {
            margin-bottom: 20px;
        }
        .form-item label {
            display: block;
            margin-bottom: 8px;
            color: #606266;
        }
        .form-item input {
            width: 100%;
            padding: 12px;
            border: 1px solid #dcdfe6;
            border-radius: 8px;
        }
        .login-btn {
            width: 100%;
            padding: 12px;
            background: #409EFF;
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
        }
        .login-type {
            margin-bottom: 20px;
        }
        .login-type label {
            margin-right: 20px;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-box">
            <h2 class="login-title">信息科管理系统</h2>
            <form id="loginForm">
                <div class="login-type">
                    <label>
                        <input type="radio" name="loginType" value="user" checked> 用户登录
                    </label>
                    <label>
                        <input type="radio" name="loginType" value="admin"> 管理员登录
                    </label>
                </div>
                <div class="form-item">
                    <label>用户名</label>
                    <input type="text" name="username" required placeholder="请输入用户名">
                </div>
                <div class="form-item">
                    <label>密码</label>
                    <input type="password" name="password" required placeholder="请输入密码">
                </div>
                <button type="submit" class="login-btn">登录</button>
            </form>
        </div>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            const formData = new FormData(this);
            const loginData = {
                username: formData.get('username'),
                password: formData.get('password')
            };

            try {
                const response = await fetch('http://localhost:3000/api/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(loginData)
                });

                const result = await response.json();
                
                if (result.success) {
                    // 保存登录信息
                    localStorage.setItem('token', result.token);
                    localStorage.setItem('userInfo', JSON.stringify(result.userInfo));
                    
                    // 根据用户类型跳转到不同页面
                    if (result.userInfo.role === 'ADMIN') {
                        window.location.href = '/index.html';
                    } else {
                        window.location.href = '/user.html';
                    }
                } else {
                    alert(result.message || '登录失败');
                }
            } catch (error) {
                console.error('登录失败:', error);
                alert('登录失败，请重试');
            }
        });
    </script>
</body>
</html> 